package com.shty.wd.utils.module.IOTools;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Properties;
import javax.swing.JOptionPane;

import org.apache.commons.io.ByteOrderMark;
import org.apache.commons.io.input.BOMInputStream;

//import org.omg.PortableServer.ServantRetentionPolicyOperations;

public class PropertyUtil {
	
	private final static String filePath = "src/main/resources/conf.properties";
	
	private static Properties props = new Properties();
	
	public static String getValues(String key){
		
		try{
			File file = new File(filePath);
			InputStreamReader inputStreamReader = null;
			if(file.exists()){
				FileInputStream fis = new FileInputStream(file);
				
				BOMInputStream bomIn = new BOMInputStream(fis, false,ByteOrderMark.UTF_8, ByteOrderMark.UTF_16LE, ByteOrderMark.UTF_16BE);
			String charset = "utf-8";
			if(bomIn.hasBOM()){
				charset = bomIn.getBOMCharsetName();
			}
			inputStreamReader = new InputStreamReader(bomIn, charset);
			}else{
				JOptionPane.showMessageDialog(null, "配置文件路径错误");
			}
			props.load(inputStreamReader);
		} catch(Exception e){
			
		}
		
		return (String) props.get(key);
	}

}
